/*
* @Author: majingyu
* @Date:   2017-05-30 16:34:11
* @Last Modified by:   jingyu.ma
* @Last Modified time: 2017-06-25 14:50:40
*/

import React, { Component }from 'react';
import { connect } from 'react-redux';
import { getCommontList } from 'action/commont.js';
import { getServiceDetails } from 'action/service.js';
import 'css/commontList.less';
import 'css/details.less';
 
class CommontList extends Component{
    constructor(props) {
        super(props);
        this.getList();
        this.getDetail();
    }  
    getList(){
        //查询评论列表
        let data = {
            pageNo: this.props.commont.commontList.pageNo,
            pageSize: 10,
            id: this.props.services.serviceId
        }
        this.props.getCommontList(data);
    }
    getDetail(){
        let data = {
            id: this.props.services.serviceId
        }
        this.props.getDetail();
    }
    render(){
        let commontList = this.props.commont ? this.props.commont.commontList.list.map((item) => {
            return (
                <div className="commontText" key={item.id}>
                    <p className="text">{item.text}</p>
                    <p className="user-mess">
                        <span className="user">{item.user}</span>
                        <span className="time">2017-03-03</span>
                    </p>
                </div>
            );
        }): <div className="list-mess">暂时无数据</div>
        return(
            <div className="content">
                <div className="detail-info">
                    <div className="line-info">
                        <lable className="title">发布人:</lable>
                        <div className="txt">{this.props.services.detail.user}</div>
                    </div>
                    <div className="line-info">
                        <lable className="title">发布课目:</lable>
                        <div className="txt">{this.props.services.detail.name}</div>
                    </div>
                    <div className="line-info">
                        <lable className="title">发布时间:</lable>
                        <div className="txt">{this.props.services.detail.time}</div>
                    </div>
                    <div className="line-info">
                        <lable className="title">有效期:</lable>
                        <div className="txt">{this.props.services.detail.dataLineTime}</div>
                    </div>
                    <div className="line-info">
                        <lable className="title">上课地址:</lable>
                        <div className="txt">{this.props.services.detail.addressSekected}</div>
                    </div>
                    <div className="line-info">
                        <lable className="title">预期价格:</lable>
                        <div className="txt">{this.props.services.detail.price}</div>
                    </div>
                    <div className="line-info">
                        <lable className="title">上课方式:</lable>
                        <div className="txt">{this.props.services.detail.stle}</div>
                    </div>
                    <div className="line-info">
                        <lable className="title">联系电话:</lable>
                        <div className="txt">{this.props.services.detail.mobile}</div>
                    </div>
                    <div className="line-info">
                        <lable className="title">联系地址:</lable>
                        <div className="txt">{this.props.services.detail.address}</div>
                    </div>
                </div>
                <div className="comment-info">
                    {commontList}
                </div>
            </div>
        );
    }
}
const commontListData = (state) => {
    return {
        commont: state.commont,
        services: state.services
    }
}
let dispatchHandle = (dispatch, getState) => {
    return {
        getCommontList(data){
            dispatch(getCommontList(data)) 
        },
        getDetail(data){
            dispatch(getServiceDetails(data));
        }
    }  
}
let visibileCommontList= connect(commontListData,dispatchHandle)(CommontList);


export default visibileCommontList;